<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>


<?php
include_once('../../libraries/esaydb.class.php');
if($_POST['username'] && $_POST['password'] && $_POST['repassword'] && $_POST['email']) {
	if($_POST['password'] != $_POST['repassword']) {
		echo "<script>alert('密码不一致');history.go(-1);</script>";//exit;
		exit;
	}
	$name 		= $_POST['username'];
	$password 	= md5($_POST['password']);
	$email 		= $_POST['email'];
	$db = new EasyDB();
	$sqlexits = 'select username from ob_user where username = ?';
	$bool = $db->querySql($sqlexits, array($name));
	if($bool) {
		echo "<script>alert('用户已经存在');history.go(-1);</script>";exit(-2);
	}
	$sql = 'insert into ob_user set username = ?, password = ?, email = ?';
	$result  = $db->querySql($sql, array($name,$password,$email));
	if($result) {
		echo "<script>alert('注册成功');window.location.href='../../login.php';</script>";
	}else{
		echo "<script>alert('注册失败');history.go(-1);</script>";
	}
}else{
	echo "<script>alert('no');history.go(-1);</script>";
}
?>
</body>
</html>
